﻿; videoplay.nsi - 修正版安装脚本
; 解决IntOp和!define语法错误问题

; --- 基本安装设置 ---
!define PRODUCT_NAME "九哈视觉"
!define PRODUCT_VERSION "1.3.1"
!define PRODUCT_PUBLISHER "四川九哈科技"
!define PRODUCT_WEB_SITE "http://www.example.com"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\vlcplay.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"

; 正确使用!define进行数学运算
!define /math BUILD_NUMBER 100 + 1  ; 示例：版本号计算

; --- 编译器设置 ---
SetCompressor /SOLID lzma
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Setup_${PRODUCT_NAME}_${PRODUCT_VERSION}.exe"
InstallDir "$PROGRAMFILES64\${PRODUCT_NAME}"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails show
ShowUnInstDetails show
RequestExecutionLevel admin

; --- 界面设置 ---
!include "MUI2.nsh"
!define MUI_ABORTWARNING
!define MUI_ICON "xh.ico"
!define MUI_UNICON "xh.ico"

; 欢迎页面
!insertmacro MUI_PAGE_WELCOME
; 目录选择页面
!insertmacro MUI_PAGE_DIRECTORY
; 安装过程页面
!insertmacro MUI_PAGE_INSTFILES
; 完成页面
!define MUI_FINISHPAGE_RUN "$INSTDIR\vlcplay.exe"
!insertmacro MUI_PAGE_FINISH

; 卸载确认页面
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

; 设置语言
!insertmacro MUI_LANGUAGE "SimpChinese"

; --- 安装部分 ---
Section "主程序" SEC01
  SetRegView 64
  SetOutPath "$INSTDIR"
  SetOverwrite try
  
  ; 替换为您的实际文件列表
  File /r "..\bin\Release\net8.0-windows\win-x64\publish\*.*"
  
  ; 创建原始快捷方式
  CreateDirectory "$SMPROGRAMS\${PRODUCT_NAME}"
  CreateShortcut "$SMPROGRAMS\${PRODUCT_NAME}\${PRODUCT_NAME}.lnk" "$INSTDIR\vlcplay.exe"
  CreateShortcut "$DESKTOP\${PRODUCT_NAME}.lnk" "$INSTDIR\vlcplay.exe"

  ; 新增：创建“九哈视觉”快捷方式，使用 xh.ico 图标
  CreateShortcut "$SMPROGRAMS\九哈视觉.lnk" "$INSTDIR\vlcplay.exe" "" "$INSTDIR\xh.ico"
SectionEnd

Section -AdditionalIcons
  WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
  CreateShortcut "$SMPROGRAMS\${PRODUCT_NAME}\网站.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
  CreateShortcut "$SMPROGRAMS\${PRODUCT_NAME}\卸载.lnk" "$INSTDIR\uninst.exe"
SectionEnd

Section -Post
  WriteUninstaller "$INSTDIR\uninst.exe"
  WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\vlcplay.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\vlcplay.exe"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd

; --- 卸载部分 ---
Section Uninstall
  ; 删除文件
  Delete "$INSTDIR\${PRODUCT_NAME}.url"
  Delete "$INSTDIR\uninst.exe"
  Delete "$INSTDIR\vlcplay.exe"
  ; 添加其他需要删除的文件
  
  ; 删除快捷方式
  Delete "$SMPROGRAMS\${PRODUCT_NAME}\*.lnk"
  Delete "$DESKTOP\${PRODUCT_NAME}.lnk"

  ; 新增：删除“九哈视觉”快捷方式
  Delete "$SMPROGRAMS\九哈视觉.lnk"
  
  ; 删除目录
  RMDir "$SMPROGRAMS\${PRODUCT_NAME}"
  RMDir "$SMPROGRAMS\九哈视觉"
  RMDir "$INSTDIR"
  
  ; 删除注册表项
  DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
  DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
  SetAutoClose true
SectionEnd





